<?php
	include 'conn.php';
	include_once 'createGuid.php';
	if ($_POST){
		$_number = $_POST['Number'];
		$_date = $_POST['date'];
		$current_date = date("ymd",time());
		//$overdue = date("ym",time())+$_date;
		$sInsert = "insert into List_Card(`CardID`,`Status`)values";
		for ($i=0;$i<$_number;$i++){
			$oGuid = new Guid();
			$sGuid = $oGuid->toString();
			$aGuid[] = join("-",array($current_date,$_date,$sGuid));
			//echo $aGuid[$i]."<br>";//
			$sInsert .="('".$aGuid[$i]."',0),";
			
			//unset($sGuid);
		}
		$sInsert = substr($sInsert,0,strlen($sInsert)-1);
		$db->query($sInsert);
	}
	
	$sSelect = "Select * from List_Card";
	$result = $db->row_query($sSelect);
?>
<table>
<form name="form1" method="post" action="">
	 <tr>
		<td>生成数量：</td>
		<td>
			<select name="Number">
				<option value="1">1张</option>
				<option value="5">5张</option>
				<option value="10">10张</option>
			</select>
		</td>
		<td>时间：</td>
		<td>
			<select name="date">
				<option value="1">1天</option>
				<option value="30">1个月</option>
				<option value="180">6个月</option>
				<option value="360">1年</option>
			</select>
		</td>
	</tr>
	<tr>
		<td colspan="2"><input type="submit" value="生成"></td>
	</tr>
</form>
</table>
<table>
<tr>
	<td align="center">CardID</td><td>Status</td><td>Active</td><td>Overdue</td><td>option</td>
</tr>
	<?php foreach ($result as $k=>$v){
		echo "<tr><td>".$v['CardID']."</td><td>".$v['Status']."</td><td>".($v['Active']?date("Y-m-d H:i:s",$v['Active']):'None')."</td><td>".($v['overdue']?date("Y-m-d H:i:s",$v['overdue']):'None')."</td><td>delete</td></tr>";
		
	}?>
</table>